package `03-dsl`.manifest

fun main() {
    /**
     * dsl 形式的mainfest
     */
    //参数是函数的函数
    manifest{
        //参数是字符串的函数
        pkg("com.test")
        //参数是字符串的函数
        permission("Internet")

        application{

            activity("MainActivity"){
                intentfilter{
                    action("android.intent.action.MAIN")
                    category("android.intent.category.LAUNCHER")
                }
            }

            service("MainActivity"){
                intentfilter{

                }
            }

            broadcast("MainActivity"){
                intentfilter{

                }
            }

            contentprovider("MainActivity"){
                intentfilter{

                }
            }
        }

    }
}

fun manifest(action :Manifest.()->Unit):Manifest{
    var manifest = Manifest();
    manifest.action()
    return manifest
}

class Manifest{
    fun pkg(str:String){}
    fun permission(str:String){}

    fun application(action :Application.()->Unit):Application{
        var application = Application()
        application.action()
        return application
    }
}

class Application{
    fun activity(str:String,action :Compant.()->Unit):Compant{
        var activity = Compant()
        activity.action()
        return activity
    }

    fun service(str:String,action :Compant.()->Unit):Compant{
        var activity = Compant()
        activity.action()
        return activity
    }

    fun broadcast(str:String,action :Compant.()->Unit):Compant{
        var activity = Compant()
        activity.action()
        return activity
    }

    fun contentprovider(str:String,action :Compant.()->Unit):Compant{
        var activity = Compant()
        activity.action()
        return activity
    }

}

class Compant{
    fun intentfilter(action :IntentFilter.()->Unit):IntentFilter{
        var intent = IntentFilter()
        intent.action()
        return intent
    }

    class IntentFilter{
        fun action(str:String){}
        fun category(str:String){}
    }
}